home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / os2 / adaptor.zip / ADAPT.ZIP / adaptor / src / wbroadca.c < prev    next >
Text File  |  1994-01-03  |  9KB  |  402 lines

  1. # include "Broadcas.h"
  2. # include "yyABroad.w"
  3. # include <stdio.h>
  4. # if defined __STDC__ | defined __cplusplus
  5. #  include <stdlib.h>
  6. # else
  7.    extern void exit ();
  8. # endif
  9. # include "Tree.h"
  10. # include "Definiti.h"
  11.  
  12. # ifndef NULL
  13. # define NULL 0L
  14. # endif
  15. # ifndef false
  16. # define false 0
  17. # endif
  18. # ifndef true
  19. # define true 1
  20. # endif
  21.  
  22. # ifdef yyInline
  23. # define yyALLOC(tree, free, max, alloc, nodesize, make, ptr, kind) \
  24.   if ((ptr = (tree) free) >= (tree) max) ptr = alloc (); \
  25.   free += nodesize [kind]; \
  26.   ptr->yyHead.yyMark = 0; \
  27.   ptr->Kind = kind;
  28. # else
  29. # define yyALLOC(tree, free, max, alloc, nodesize, make, ptr, kind) ptr = make (kind);
  30. # endif
  31.  
  32. # define yyWrite(s) (void) fputs (s, yyf)
  33. # define yyWriteNl (void) fputc ('\n', yyf)
  34.  
  35. # line 29 "AdaptBroadcast.puma"
  36.  
  37.  
  38. # include <stdio.h>
  39.  
  40. # include "Idents.h"
  41. # include "StringMe.h"
  42.  
  43. # include "protocol.h"
  44.  
  45. # include "Types.h"
  46. # include "Expressi.h"     /* MakeSliceExp */
  47. # include "Movement.h"   /* FirstArrayElement */
  48. # include "Transfor.h"       /* IsHost, MakeUsedVar... */
  49. # include "Dalib.h"           /* IsHost, MakeUsedVar... */
  50. # include "Shapes.h"          /* MakeFullShape  */
  51.  
  52.  
  53. static FILE * yyf = stdout;
  54.  
  55. static void yyAbort
  56. # ifdef __cplusplus
  57.  (char * yyFunction)
  58. # else
  59.  (yyFunction) char * yyFunction;
  60. # endif
  61. {
  62.  (void) fprintf (stderr, "Error: module AdaptBroadcast, routine %s failed\n", yyFunction);
  63.  exit (1);
  64. }
  65.  
  66. tTree MakeParamBroadcast ARGS((tTree t));
  67. tTree MakeReadSpecBroadcast ARGS((tTree t));
  68. tTree MakeBroadcast ARGS((tTree t));
  69. static tTree Overlapping ARGS((tTree t));
  70. static tTree TakeWholeVar ARGS((tTree v));
  71.  
  72. tTree MakeParamBroadcast
  73. # if defined __STDC__ | defined __cplusplus
  74. (register tTree t)
  75. # else
  76. (t)
  77.  register tTree t;
  78. # endif
  79. {
  80. # line 56 "AdaptBroadcast.puma"
  81.  
  82. tTree h, newacf;
  83. int dist;
  84.  
  85.   if (t->Kind == kBTP_LIST) {
  86. # line 61 "AdaptBroadcast.puma"
  87.    return CombineACF (MakeParamBroadcast (t->BTP_LIST.Elem), MakeParamBroadcast (t->BTP_LIST.Next));
  88.  
  89.   }
  90.   if (t->Kind == kBTP_EMPTY) {
  91. # line 65 "AdaptBroadcast.puma"
  92.    return (NoTree);
  93.  
  94.   }
  95.   if (t->Kind == kVAR_PARAM) {
  96.   if (t->VAR_PARAM.V->Kind == kADDR) {
  97. # line 69 "AdaptBroadcast.puma"
  98.    return NoTree;
  99.  
  100.   }
  101. # line 77 "AdaptBroadcast.puma"
  102.   {
  103. # line 78 "AdaptBroadcast.puma"
  104.    if (! ((target_model == UNI_PROC))) goto yyL4;
  105.   }
  106.    return NoTree;
  107. yyL4:;
  108.  
  109.   if (t->VAR_PARAM.V->Kind == kUSED_VAR) {
  110.   if (t->VAR_PARAM.V->USED_VAR.VARNAME->VAR_OBJ.Object->Kind == kVarObject) {
  111.   if (t->VAR_PARAM.V->USED_VAR.VARNAME->VAR_OBJ.Object->VarObject.Kind->Kind == kVarConstant) {
  112. # line 82 "AdaptBroadcast.puma"
  113.    return NoTree;
  114.  
  115.   }
  116.   }
  117.   }
  118. # line 89 "AdaptBroadcast.puma"
  119.   {
  120. # line 90 "AdaptBroadcast.puma"
  121.  dist = TreeDistribution (t->VAR_PARAM.V);
  122.       if (dist == -1)
  123.          {
  124.            newacf = NoTree;
  125.          }
  126.       else if (dist == 0)
  127.          {
  128.            newacf = MakeBroadcast (t->VAR_PARAM.V);
  129.          }
  130.       else
  131.          { printf ("Illegal Distribution in MakeParamBroadcast\n");
  132.            exit (-1);
  133.          }
  134.  
  135.   }
  136.    return newacf;
  137.  
  138.   }
  139.   if (t->Kind == kFUNC_PARAM) {
  140. # line 113 "AdaptBroadcast.puma"
  141.    return NoTree;
  142.  
  143.   }
  144.   if (t->Kind == kPROC_PARAM) {
  145. # line 117 "AdaptBroadcast.puma"
  146.    return NoTree;
  147.  
  148.   }
  149. # line 121 "AdaptBroadcast.puma"
  150.   {
  151. # line 122 "AdaptBroadcast.puma"
  152.    failure_protocol ("AdaptBroadcast", "MakeParamBroadcast", t);
  153.   }
  154.    return NoTree;
  155.  
  156. }
  157.  
  158. tTree MakeReadSpecBroadcast
  159. # if defined __STDC__ | defined __cplusplus
  160. (register tTree t)
  161. # else
  162. (t)
  163.  register tTree t;
  164. # endif
  165. {
  166.  
  167.   switch (t->Kind) {
  168.   case kBTP_LIST:
  169. # line 138 "AdaptBroadcast.puma"
  170.    return CombineACF (MakeReadSpecBroadcast (t->BTP_LIST.Elem), MakeReadSpecBroadcast (t->BTP_LIST.Next));
  171.  
  172.   case kBTP_EMPTY:
  173. # line 143 "AdaptBroadcast.puma"
  174.    return NoTree;
  175.  
  176.   case kNAMED_PARAM:
  177. # line 147 "AdaptBroadcast.puma"
  178.    return MakeReadSpecBroadcast (t->NAMED_PARAM.VAL);
  179.  
  180.   case kVAR_PARAM:
  181. # line 151 "AdaptBroadcast.puma"
  182.   {
  183. # line 152 "AdaptBroadcast.puma"
  184.    if (! ((target_model == UNI_PROC))) goto yyL4;
  185.   }
  186.    return NoTree;
  187. yyL4:;
  188.  
  189.   if (t->VAR_PARAM.V->Kind == kUSED_VAR) {
  190.   if (t->VAR_PARAM.V->USED_VAR.VARNAME->VAR_OBJ.Object->Kind == kNameListObject) {
  191.   if (t->VAR_PARAM.V->USED_VAR.VARNAME->VAR_OBJ.Object->NameListObject.decl->Kind == kNAMELIST_DECL) {
  192. # line 156 "AdaptBroadcast.puma"
  193.    return MakeReadSpecBroadcast (t->VAR_PARAM.V->USED_VAR.VARNAME->VAR_OBJ.Object->NameListObject.decl->NAMELIST_DECL.IDS);
  194.  
  195.   }
  196.   }
  197.   }
  198. # line 163 "AdaptBroadcast.puma"
  199.    return NoTree;
  200.  
  201.   case kDECL_LIST:
  202. # line 167 "AdaptBroadcast.puma"
  203.    return CombineACF (MakeReadSpecBroadcast (t->DECL_LIST.Elem), MakeReadSpecBroadcast (t->DECL_LIST.Next));
  204.  
  205.   case kDECL_EMPTY:
  206. # line 172 "AdaptBroadcast.puma"
  207.    return NoTree;
  208.  
  209.   case kVAR_DECL:
  210. # line 176 "AdaptBroadcast.puma"
  211.  {
  212.   int dist;
  213.   tDefinitions Obj;
  214.   tTree var;
  215.   {
  216. # line 180 "AdaptBroadcast.puma"
  217.  
  218. # line 181 "AdaptBroadcast.puma"
  219.  
  220. # line 182 "AdaptBroadcast.puma"
  221.  
  222. # line 184 "AdaptBroadcast.puma"
  223.    Obj = GetLocalDecl (t->VAR_DECL.Name);
  224. # line 186 "AdaptBroadcast.puma"
  225.  dist = VarDistribution (Obj);
  226.       if (dist == -1)
  227.          {
  228.            var = NoTree;
  229.          }
  230.       else if (dist == 0)
  231.          {
  232.            var = mVAR_OBJ (t->VAR_DECL.Pos, t->VAR_DECL.Name);
  233.            var->VAR_OBJ.Object = Obj;
  234.            var = MakeBroadcast (mUSED_VAR (var));
  235.          }
  236.       else
  237.          { printf ("Illegal Distribution in MakeReadSpecBroadcast\n");
  238.            exit (-1);
  239.          }
  240.  
  241.   }
  242.   {
  243.    return var;
  244.   }
  245.  }
  246.  
  247.   }
  248.  
  249. # line 205 "AdaptBroadcast.puma"
  250.   {
  251. # line 206 "AdaptBroadcast.puma"
  252.    failure_protocol ("AdaptBroadcast", "MakeReadSpecBroadcast", t);
  253.   }
  254.    return NoTree;
  255.  
  256. }
  257.  
  258. tTree MakeBroadcast
  259. # if defined __STDC__ | defined __cplusplus
  260. (register tTree t)
  261. # else
  262. (t)
  263.  register tTree t;
  264. # endif
  265. {
  266. # line 220 "AdaptBroadcast.puma"
  267.  
  268. tTree from, size, stat, broadcast_var;
  269. tIdent pname;
  270. int sends;
  271.  
  272. # line 228 "AdaptBroadcast.puma"
  273.   {
  274. # line 229 "AdaptBroadcast.puma"
  275.  broadcast_var = Overlapping (t);
  276.  
  277.     if (TreeRank(broadcast_var) >= 1)
  278.        broadcast_var = MakeFullShape (broadcast_var);
  279.     if (target_model == ONLY_NODE)
  280.        sends = 1;
  281.       else
  282.        sends = 0;
  283.     from = mVAR_PARAM (mADDR (mCONST_EXP (mINT_CONSTANT (sends))));
  284.     size = ExpToVarParam (MakeSizeExp (broadcast_var));
  285.     if (TreeRank(broadcast_var) >= 1)
  286.        broadcast_var = FirstArrayElement (broadcast_var);
  287.     pname = MakeDalibId ("broadcast");
  288.     stat = mCALL_STMT (
  289.               mPROC_OBJ (pname),
  290.                mBTP_LIST (mVAR_PARAM (broadcast_var),
  291.                 mBTP_LIST (size,
  292.                  mBTP_LIST (from,
  293.                   mBTP_EMPTY ()))));
  294.     stat = mACF_BASIC (stat);
  295.  
  296.   }
  297.    return stat;
  298.  
  299. }
  300.  
  301. static tTree Overlapping
  302. # if defined __STDC__ | defined __cplusplus
  303. (register tTree t)
  304. # else
  305. (t)
  306.  register tTree t;
  307. # endif
  308. {
  309.   if (t->Kind == kDO_VAR) {
  310.   if (t->DO_VAR.BODY->Kind == kBTV_LIST) {
  311.   if (t->DO_VAR.BODY->BTV_LIST.Next->Kind == kBTV_EMPTY) {
  312. # line 263 "AdaptBroadcast.puma"
  313.    return TakeWholeVar (t->DO_VAR.BODY->BTV_LIST.Elem);
  314.  
  315.   }
  316. # line 270 "AdaptBroadcast.puma"
  317.   {
  318. # line 272 "AdaptBroadcast.puma"
  319.    error_protocol ("Broadcast: Too many variables in the variable list");
  320.   }
  321.    return TakeWholeVar (t->DO_VAR.BODY->BTV_LIST.Elem);
  322.  
  323.   }
  324.   }
  325.   if (t->Kind == kINDEXED_VAR) {
  326. # line 276 "AdaptBroadcast.puma"
  327.   {
  328. # line 277 "AdaptBroadcast.puma"
  329.    if (! (IsContiguousSection (t) == true)) goto yyL3;
  330.   }
  331.    return t;
  332. yyL3:;
  333.  
  334. # line 283 "AdaptBroadcast.puma"
  335.    return t->INDEXED_VAR.IND_VAR;
  336.  
  337.   }
  338.   if (t->Kind == kUSED_VAR) {
  339. # line 288 "AdaptBroadcast.puma"
  340.    return t;
  341.  
  342.   }
  343. # line 292 "AdaptBroadcast.puma"
  344.   {
  345. # line 293 "AdaptBroadcast.puma"
  346.    failure_protocol ("AdaptBroadcast", "Overlapping", t);
  347.   }
  348.    return t;
  349.  
  350. }
  351.  
  352. static tTree TakeWholeVar
  353. # if defined __STDC__ | defined __cplusplus
  354. (register tTree v)
  355. # else
  356. (v)
  357.  register tTree v;
  358. # endif
  359. {
  360.   if (v->Kind == kINDEXED_VAR) {
  361. # line 305 "AdaptBroadcast.puma"
  362.    return v->INDEXED_VAR.IND_VAR;
  363.  
  364.   }
  365.   if (v->Kind == kUSED_VAR) {
  366. # line 309 "AdaptBroadcast.puma"
  367.    return v;
  368.  
  369.   }
  370.   if (v->Kind == kDO_VAR) {
  371.   if (v->DO_VAR.BODY->Kind == kBTV_LIST) {
  372.   if (v->DO_VAR.BODY->BTV_LIST.Next->Kind == kBTV_EMPTY) {
  373. # line 313 "AdaptBroadcast.puma"
  374.    return TakeWholeVar (v->DO_VAR.BODY->BTV_LIST.Elem);
  375.  
  376.   }
  377. # line 320 "AdaptBroadcast.puma"
  378.   {
  379. # line 322 "AdaptBroadcast.puma"
  380.    error_protocol ("Broadcast: Too many variables in the variable list");
  381.   }
  382.    return TakeWholeVar (v->DO_VAR.BODY->BTV_LIST.Elem);
  383.  
  384.   }
  385.   }
  386. # line 326 "AdaptBroadcast.puma"
  387.   {
  388. # line 327 "AdaptBroadcast.puma"
  389.    failure_protocol ("AdaptBroadcast", "TakeWholeVar", v);
  390.   }
  391.    return v;
  392.  
  393. }
  394.  
  395. void BeginAdaptBroadcast ()
  396. {
  397. }
  398.  
  399. void CloseAdaptBroadcast ()
  400. {
  401. }
  402.